package scoutobahn.xml.automaton;

import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.DefaultHandler;
/**
 * Sax content handler implementation for parsing osm files.
 * @author mark
 *
 */
public class OsmSaxHandler extends DefaultHandler {

    private ParserState currentState;
    private StateManager manager;
    /**
     * Constructs a new OsmSaxHandler with the given OsmItemStreamListener.
     * @param listener OsmItemStream listener to handle the found elements
     */
    public OsmSaxHandler(final OsmItemStreamManager listener) {
        this.manager = new StateManager(listener);
    }

    @Override
    public void startDocument() throws SAXException {
        this.currentState = manager.getUndefinedState();
    }

    @Override
    public void startElement(final String nameSpace,
            final String localName, final String qName,
            final Attributes attr) throws SAXException {
       this.currentState = this.currentState.
               startElement(nameSpace, localName, qName, attr);
    }

    @Override
    public void endElement(final String namespace,
            final String localName, final String qName)
            throws SAXException {
    this.currentState = this.currentState.
            endElement(namespace, localName, qName);

    }
}
